package com.yulinlin.websocket.server.controller;

import com.yulinlin.common.domain.RequestPo;
import com.yulinlin.common.domain.ResponseVo;
import com.yulinlin.websocket.common.domain.FrameMessage;
import com.yulinlin.websocket.common.domain.TopicEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "消息")
@RequestMapping("config")
@RestController
public class MessageController {

    @Autowired
    private RedisTemplate redisTemplate;

    @ApiOperation("发送消息")
    @RequestMapping("sendMessage")
    public ResponseVo sendMessage(@RequestBody RequestPo<FrameMessage> po){
        redisTemplate.convertAndSend(TopicEnum.websocket,po.getData());
        return ResponseVo.newInstance(true);
    }

}
